package cn.kgc.mes.storage.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.kgc.mes.common.annotation.Log;
import cn.kgc.mes.common.core.controller.BaseController;
import cn.kgc.mes.common.core.domain.AjaxResult;
import cn.kgc.mes.common.enums.BusinessType;
import cn.kgc.mes.storage.domain.ItType1;
import cn.kgc.mes.storage.service.IItType1Service;
import cn.kgc.mes.common.utils.poi.ExcelUtil;

/**
 * 物料分类Controller
 * 
 * @author ydw
 * @date 2025-09-12
 */
@RestController
@RequestMapping("/type1/type1")
public class ItType1Controller extends BaseController
{
    @Autowired
    private IItType1Service itType1Service;

    /**
     * 查询物料分类列表
     */
//    @PreAuthorize("@ss.hasPermi('type1:type1:list')")
    @GetMapping("/list")
    public AjaxResult list(ItType1 itType1)
    {
        List<ItType1> list = itType1Service.selectItType1List(itType1);
        return success(list);
    }

    /**
     * 导出物料分类列表
     */
//    @PreAuthorize("@ss.hasPermi('type1:type1:export')")
    @Log(title = "物料分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItType1 itType1)
    {
        List<ItType1> list = itType1Service.selectItType1List(itType1);
        ExcelUtil<ItType1> util = new ExcelUtil<ItType1>(ItType1.class);
        util.exportExcel(response, list, "物料分类数据");
    }

    /**
     * 获取物料分类详细信息
     */
//    @PreAuthorize("@ss.hasPermi('type1:type1:query')")
    @GetMapping(value = "/{itemTypeId}")
    public AjaxResult getInfo(@PathVariable("itemTypeId") Long itemTypeId)
    {
        return success(itType1Service.selectItType1ByItemTypeId(itemTypeId));
    }

    /**
     * 新增物料分类
     */
//    @PreAuthorize("@ss.hasPermi('type1:type1:add')")
    @Log(title = "物料分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItType1 itType1)
    {
        return toAjax(itType1Service.insertItType1(itType1));
    }

    /**
     * 修改物料分类
     */
//    @PreAuthorize("@ss.hasPermi('type1:type1:edit')")
    @Log(title = "物料分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItType1 itType1)
    {
        return toAjax(itType1Service.updateItType1(itType1));
    }

    /**
     * 删除物料分类
     */
//    @PreAuthorize("@ss.hasPermi('type1:type1:remove')")
    @Log(title = "物料分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemTypeIds}")
    public AjaxResult remove(@PathVariable Long[] itemTypeIds)
    {
        return toAjax(itType1Service.deleteItType1ByItemTypeIds(itemTypeIds));
    }
}
